import axios from 'axios'

var base = 'http://127.0.0.1:8848';

// 上传图片
export function upload(formdata) {
	return axios({
		url: `${base}/api/image`,
		method: 'post',
		data: {
			image: formdata
		}
	})
}
//上传附件
export function uploadFile(data){
	return axios({
		url: `${base}/annex/file`,
		method: 'post',
		data: data
	})
}

// 下载附件
export function getAnnex(id){
	return axios({
		method: 'get',
		url: `${base}/annex/get/${id}`
	})
}

//上传头像
export function uploadFace(formdata,type) {
	return axios({
		url: `${base}/api/image`,
		method: 'post',
		data: {
			image: formdata,
			type:'face',
			imgType:type
		}
	})
}

//注册
export function Regist(data) {
	return axios({
		method: 'post',
		url: `${base}/api/regist`,
		data: data,
	})
}

//登录
export function login(data) {
	return axios({
		method: 'post',
		url: `${base}/api/login`,
		data: data,
	})
}
//获取用户个人信息
export function getuserinfo() {
	return axios({
		method: 'get',
		url: `${base}/my/userinfo`
	})
}

//获取某人个人信息
export function getsomeoneinfo(id) {
	return axios({
		method: 'get',
		url: `${base}/my/someoneinfo/${id}`
	})
}
//获取文章
export function getarticle() {
	return axios({
		method: 'get',
		url: `${base}/article/get`
	})
}

//获取最热文章
export function gethotarticle() {
	return axios({
		method: 'get',
		url: `${base}/article/hot`
	})
}
//获取某个文章
export function getonearticle(id) {
	return axios({
		method: 'get',
		url: `${base}/article/get/${id}`
	})
}

//收藏文章
export function starArticle(id,authorid,iscollect){
	return axios({
		method:'post',
		url:`${base}/article/star`,
		data:{
			articleid:id,
			authorid,
			iscollect:iscollect
		}
	})
}
// 获取评论
export function getcomment(id) {
	return axios({
		method: 'get',
		url: `${base}/comment/search/${id}`
	})
}
//评论/回复
export function recall(data) {
	return axios({
		method: 'post',
		url: `${base}/comment/add`,
		data: data,
	})
}
//删除评论
export function deletecomment(id) {
	return axios({
		method: 'post',
		url: `${base}/comment/delete`,
		data: {
			id: id
		},
	})
}
//获取所有知识库
export function getallcategory() {
	return axios({
		method: 'get',
		url: `${base}/store/all`,
	})
}
//获取最新十个知识库
export function getnewcategory() {
	return axios({
		method: 'get',
		url: `${base}/store/getnew`,
	})
}
//根据知识库获取文章
export function getarticlebystore(id) {
	return axios({
		method: 'get',
		url: `${base}/article/store/${id}`,
	})
}
// 根据id获取知识库
export function getcatebyid(id) {
	return axios({
		method: 'get',
		url: `${base}/store/get/${id}`,
	})
}
//新增知识库
export function addcategory(data) {
	return axios({
		method: 'post',
		url: `${base}/store/add`,
		data: data
	})
}
//加入知识库
export function joinStore(id){
	return axios({
		method:'post',
		url:`${base}/store/join/${id}`
	})
}
//查找知识库成员
export function getStoreMember(id){
	return axios({
		method:'get',
		url:`${base}/store/member/${id}`
	})
}
// 查找知识库所属文件
export function getStoreFile(id){
	return axios({
		method:'get',
		url:`${base}/store/file/${id}`,
	})
}
// 新建文件夹/附件
export function createFiles(data){
	return axios({
		method:'post',
		url:`${base}/store/file/upload`,
		data:data
	})
}


//删除文件
export function deleteFile(id,type){
	return axios({
		method:'post',
		url:`${base}/store/file/delete`,
		data:{
			id,
			type
		}
	})
}
//改文件夹名字

export function updateFileName(id,filetitle){
	return axios({
		method:'post',
		url:`${base}/store/file/rename`,
		data:{
			id,
			filetitle,
		}
	})
}
// 更新文章
export function editarticle(data,param) {
	return axios({
		method: 'post',
		url: `${base}/article/update`,
		data: {
			...data,
			...param
		},
	})
}
//删除文章
export function deleteArticle(id) {
	return axios({
		method: 'post',
		url: `${base}/article/delete`,
		data: {
			id: id
		}
	})
}
//发布文章
export function publisharticle(data,param) {
	return axios({
		method: 'post',
		url: `${base}/article/publish`,
		data: {
			...data,
			...param
		},
	})
}
//获取某人的文章
export function getsomeonearticle(id) {
	return axios({
		method: 'get',
		url: `${base}/article/author/${id}`,
	})
}
//更新用户昵称
export function updatename(data) {
	return axios({
		method: 'post',
		url: `${base}/my/updateinfo`,
		data: data
	})
}
//更新用户密码
export function updatepwd(data) {
	return axios({
		method: 'post',
		url: `${base}/my/updatepwd`,
		data: data
	})
}
// 获取个人草稿箱文章
export function getnopub() {
	return axios({
		method: 'get',
		url: `${base}/my/article/nopub`,
	})
}
// 获取个人消息
export function getuserMessage(){
	return axios({
		method:'get',
		url:`${base}/collect/message`
	})
} 
// 获取未读消息条数
export function getnoreadmesLength(){
	return axios({
		method:'get',
		url:`${base}/collect/noread/length`
	})
}
//获取收藏夹
export function getStarList(){
	return axios({
		method:'get',
		url:`${base}/collect/my`
	})
}
// 迁移文件
export function moveFile(data){
	return axios({
		method:'post',
		url:`${base}/store/file/move`,
		data:data
	})
}